using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace View
{
    public class GameCamera
    {

        private int gameScreenWidth = 500;
        private int gameScreenHeight = 500;

        private float gameLevelWidth;
        private float gameLevelHeight;

        private Vector2 borderSize;

        private Vector2 scale;

        public GameCamera(Vector2 borderSize, float gameLevelWidth, float gameLevelHeight)
        {
            this.borderSize = borderSize;
            this.gameLevelWidth = gameLevelWidth;
            this.gameLevelHeight = gameLevelHeight;
            setScale();
        }

        public void setScale()
        {
            scale.x = (gameScreenWidth) / gameLevelWidth;
            scale.y = (gameScreenHeight) / gameLevelHeight;
        }

        /// <summary>
        /// Create camera with desired game screen size.
        /// </summary>
        public GameCamera(int gameScreenWidth, int gameScreenHeight)
        {
            this.gameScreenWidth = gameScreenWidth;
            this.gameScreenHeight = gameScreenHeight;
        }

        /// <summary>
        /// Takes x, y logical positions and returns a Vector2 in visual representation.
        /// </summary>
        public Vector2 getVisualCoordinates(Vector2 logicalPos)
        {
            float visualX = (logicalPos.x) * gameScreenWidth;
            float visualY = (logicalPos.y) * gameScreenHeight;

            return new Vector2(visualX, visualY);
        }

        public Vector2 getLogicalCoordinates(Vector2 visualPos)
        {
            float logicalX = visualPos.x / gameScreenWidth;
            float logicalY = visualPos.y / gameScreenHeight;

            return new Vector2(logicalX, logicalY);
        }

        public Vector2 getVisualSizeWithRadius(float radius)
        {
            float visualWidth = radius * 2 * gameScreenWidth;
            float visualHeight = radius * 2 * gameScreenHeight;

            return new Vector2(visualWidth, visualHeight);
        }

        /// <summary>
        /// Takes width and hight in logical measurment and returns a Vector2 in visual representation (pixles).
        /// </summary>
        public Vector2 getVisualSize(float logicalWidth, float logicalHeight)
        {
            float visualWidth = logicalWidth * gameScreenWidth;
            float visualHeight = logicalHeight * gameScreenHeight;

            return new Vector2(visualWidth, visualHeight);
        }

        /// <summary>
        /// Fits the game to current screen resolution as a square.
        /// </summary>
        public void fitGameToScreenAsSquare()
        {
            if (Screen.width > Screen.height)
            {
                gameScreenHeight = Screen.height;
                gameScreenWidth = Screen.height;
            }
            else
            {
                gameScreenHeight = Screen.width;
                gameScreenWidth = Screen.width;
            }

            setScale();
        }

        /// <summary>
        /// Fits the game to current screen resolution.
        /// </summary>
        public void fitGameToScreen()
        {
            gameScreenWidth = Screen.width;
            gameScreenHeight = Screen.height;

            setScale();
        }
    }
}
